//
//  KKVisitorViewController.swift
//  KKWeibo
//
//  Created by kassia on 16/7/9.
//  Copyright © 2016年 kassia. All rights reserved.
//

import UIKit

class KKVisitorViewController: UITableViewController {
    
    //登录标记
    var isLogin: Bool = KKUserAccountModel.sharedUserAccount.isLogin
    
    var vistorView: KKVistorView?
 
    override func loadView() {
        
        if isLogin {
        
            super.loadView()//登录状态时的状态
            
        } else {
            
           vistorView = KKVistorView()//创建访客视图
        
            vistorView?.loginClosure = {[weak self] in
            
            self?.creatVisitorController()
                
            }
           view = vistorView
            
            setUpNavUI()//登录和注册按钮
        }
        
        
    }
    
   private func setUpNavUI() {
        
        //自定义视图
        navigationItem.leftBarButtonItem = UIBarButtonItem(target: self, title: "登录", action: "LoginAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(target: self, title: "注册", action: "RegisterAction")
        
    }
    
   @objc private func LoginAction() {
    
    creatVisitorController()
    
    }
    
    @objc private func RegisterAction() {
        
        creatVisitorController()
    }
    
    //创建登录控制器
    func creatVisitorController() {
        
        let oAuthController = KKOAuthLoginController()
        
        oAuthController.view.backgroundColor = UIColor.whiteColor()
        
        let nav = UINavigationController(rootViewController: oAuthController)
        
       presentViewController(nav, animated: true, completion: nil)

    }
    
    
}
